﻿using System;
using Mads.CoreDomain.Enumerations;
using System.Runtime.Serialization;

namespace Mads.CoreDomain
{
  /// <summary>
  /// Represents one train ticket.
  /// </summary>
  
  [DataContract]
  public class Ticket : KeyAbstraction
  {
    #region public properties
    /// <summary>
    /// More informative id of the ticket.
    /// Not required.
    /// </summary>
    [DataMember]
    public string LogicalID { get; set; }

    /// <summary>
    /// Seat assigned to this ticket.
    /// </summary>
    [DataMember]
    public Seat Seat { get; private set; }

    /// <summary>
    /// Ticket departure station.
    /// </summary>
    [DataMember]
    public RouteStop StartStation { get; set; }

    /// <summary>
    /// Ticket arrival station.
    /// </summary>
    [DataMember]
    public RouteStop EndStation { get; set; }

    /// <summary>
    /// State of the ticket: free, taken, etc.
    /// </summary>
    //[DataMember]
    public TicketState State { get; set; }

    /// <summary>
    /// A person mentioned in the ticket.
    /// Not required (for tickets that are not bought).
    /// </summary>
    //[DataMember]
    public TicketOwner Owner { get; set; }

    /// <summary>
    /// Electronic order that includes this ticket.
    /// Not required.
    /// </summary>
    //[DataMember]
    public Order Order { get; set; }

    /// <summary>
    /// User that ordered/bought ticket.
    /// Not required.
    /// </summary>
    public User Buyer { get; set; }

    /// <summary>
    /// If this ticket is booked, this is the date and time of booking end.
    /// Not required.
    /// </summary>
    public DateTime? BookedUntil { get; set; }

    /// <summary>
    /// Date and time when this ticket was bought/booked.
    /// Not required.
    /// </summary>
    public DateTime? Bought { get; set; }
    #endregion

    public Ticket(
      Seat seat,
      RouteStop startStation,
      RouteStop endStation,
      TicketState state)
    {
      if (seat == null)
      {
        throw new ArgumentNullException("seat");
      }
      if (startStation == null)
      {
        throw new ArgumentNullException("startStation");
      }
      if (endStation == null)
      {
        throw new ArgumentNullException("endStation");
      }

      Seat = seat;
      StartStation = startStation;
      EndStation = endStation;
      State = state;
    }
  }
}